package com.sx.shop.util;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import com.sx.shop.entity.User;



public class SessionUtil {

	// 获取当前的Request
	public static HttpServletRequest getRequest() {
		return ((ServletRequestAttributes) RequestContextHolder.currentRequestAttributes()).getRequest();
	}

	// 获取当前的Session
	public static HttpSession getSession() {
		return getRequest().getSession();
	}

	//获取当前登录账号
	public static User getCurrentUser() {
		Object obj = getSession().getAttribute("current");
		if (obj != null && obj instanceof User) {
			return (User) obj;
		}
		return null;
	}

}
